<?php


namespace App\Models\Mini;

use App\Models\AdminEstate;
use App\Models\Notice;
use Illuminate\Database\Eloquent\Builder;

class NoticeModel extends Notice
{

    //全局查询条件
    protected static function booted()
    {
        static::addGlobalScope('age', function (Builder $builder) {
            $builder->where(['status' => 1, 'is_show' => 1]);
        });
    }

    //隐藏字段
    protected $hidden = [
        'community_id', 'start_time', 'end_time', 'admin_user', 'is_show', 'status', 'community_name', 'estate_id'
    ];

    /**
     * Notes: 关联发布者
     * User: lstink
     * Date: 2021/3/4
     * Time: 3:41 下午
     * @return \Illuminate\Database\Eloquent\Relations\HasOne
     */
    public function author(): \Illuminate\Database\Eloquent\Relations\HasOne
    {
        return $this->hasOne(AdminEstate::class, 'id', 'admin_user')->select(['id', 'username']);
    }
}
